package com.ruoyi.lvlian.controller;

import java.util.List;

import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.lvlian.dto.LhsTricycleDto;
import com.ruoyi.lvlian.vo.DriverInfoVo;
import com.ruoyi.lvlian.vo.SimpleSysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.lvlian.domain.LhsTricycle;
import com.ruoyi.lvlian.service.ILhsTricycleService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;

import javax.validation.constraints.NotBlank;

/**
 * 商户三轮车司机信息Controller
 *
 * @author liyuxi
 * @date 2025-10-09
 */
@RestController
@RequestMapping("/tricycle")
@Api(value = "莱回收-商户三轮车司机信息", tags = "商户三轮车司机信息Controller")
public class LhsTricycleController extends BaseController {
    @Autowired
    private ILhsTricycleService lhsTricycleService;

    /**
     * 查询商户三轮车司机信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(LhsTricycleDto lhsTricycle) {
        startPage();
        List<SimpleSysUser> list = lhsTricycleService.selectLhsTricycleList(lhsTricycle);
        return getDataTable(list);
    }


    /**
     * 获取商户三轮车司机信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(lhsTricycleService.selectLhsTricycleById(id));
    }



    /**
     * 修改商户三轮车司机信息
     */
    @Log(title = "商户三轮车司机信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LhsTricycle lhsTricycle) {
        return toAjax(lhsTricycleService.updateLhsTricycle(lhsTricycle));
    }

    /**
     * 删除商户三轮车司机信息
     */

    @Log(title = "商户三轮车司机信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public AjaxResult remove(@RequestBody String[] ids) {
        return toAjax(lhsTricycleService.deleteLhsTricycleByIds(ids));
    }


    @ApiOperation("通过手机号码查询司机信息")
    @GetMapping("/getInfoByPhone")
    public AjaxResult getInfoByPhone(@RequestParam @NotBlank(message = "手机号码不能为空") String phone, @RequestParam(defaultValue = "小程序") String dataSource ) {
        boolean validPhoneNumber = StringUtils.isValidPhoneNumber(phone);
        if (validPhoneNumber) {
            SimpleSysUser driver = lhsTricycleService.getInfoByPhone(phone,dataSource);

            if (driver == null) {
                return error("该司机不存在");
            }
            return success(driver);
        } else {
            return error("号码不对");
        }

    }

}
